import axios from 'axios'
import * as constents from './createTypes'
import { fromJS } from 'immutable'


const changeAction = (result) => ({
    type: constents.CHANGE_HOME_DATA,
    articleList: result.articleList,
    recommendList: result.recommendList

})
const getmoreInfo = (data, nextPage) => ({
    type: constents.GET_MORE_INFO,
    data : fromJS(data),
    nextPage
})


export const getListInfo = () => {
    return (dispatch) => {
        axios.get('/api/home.json').then(res => {
            // console.log(res.data)
            const result = res.data.data
            const action = changeAction(result)
            dispatch(action)
        })
    }
}


//list 列表
export const getMore = (nextPage) => {
    return dispatch => {
        axios.get('/api/homeList.json?page=' + nextPage).then(res => {
            const result = res.data.data
            dispatch(getmoreInfo(result, nextPage + 1))
        })
    }
}